package pictionary2;


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Viper
 */
public class Escritor implements Runnable{
    Socket s;
    private MSN msn;
    BufferedReader br;
    ObjectOutputStream oos;
    PrintStream ps;
    int num;

    public Escritor(Socket s, MSN m, int o) throws IOException {
        this.s = s;
        msn= m;
        conectaEscritor();
        num=o;

    }
    public void conectaEscritor() throws IOException{
        br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream aux= s.getOutputStream();

       // ps = new PrintStream(aux);
        oos= new ObjectOutputStream(aux);
    }

    public void escribe() throws Exception{
        String str= "";
        //System.out.println("se esta escribiendo");
        str=msn.getContactoActual().getMiMensaje().getText();
        msn.getContactoActual().getMiMensaje().setText("");
        //oos.flush();
        oos.writeObject(str);
        oos.flush();
        
    }


    public void escribe(int i) throws Exception{
        //System.out.println("se esta escribiendo");
        //Point []p=msn.getPaint().getPoints();
        //i=msn.getPaint().getPointCount();

        //oos.flush();
        oos.writeObject(msn.getPaint());
        oos.flush();
      //  oos.writeObject(i);
       // oos.flush();

    }




 /********   public void escribe() throws Exception{
        String str= "";
        str=msn.getContactoActual().getMiMensaje().getText();
        msn.getContactoActual().getMiMensaje().setText("");
        //oos.flush();
        ps.println(str);
        ps.flush();

    }*/

  /*  public void escribe(PaintPanel p) throws Exception{
        oos.writeObject(p);
        oos.flush();
    }*/

    public void run() {
        try {
            if(num==0) {
                escribe();
            }else if(num==1){
                escribe(1);
            }
        } catch (Exception ex) {
            Logger.getLogger(Escritor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
